home *** CD-ROM | disk | FTP | other *** search
- Path: logica.co.uk!apple
- From: jjk@lbvrtda.logica.com (Jan Just [JJ] Keijser)
- Newsgroups: comp.lang.c,comp.lang.c++,comp.os.msdos.programmer
- Subject: Re: Device Drivers
- Date: Wed, 31 Jan 96 08:56:01 GMT
- Organization: Logica BV
- Message-ID: <4enaqh$497@romeo.logica.co.uk>
- References: <4em26p$el1@canopus.cc.umanitoba.ca>
- NNTP-Posting-Host: 158.234.122.115
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4em26p$el1@canopus.cc.umanitoba.ca>,
- natewild@mbnet.mb.ca (Nathan T. Wild) wrote:
- >I would like to be able to make device drivers in C. I writing an
- >application which uses loadable modules for some of it's functions.
- >
- >Currently these functions are written in Assembly language. The
- >assembled executable code is stripped of it's EXE header and the
- >contents is written directly to memory... Then a function pointer is
- >set to point to this code.
- >
- >This works... But how can I go about generating these executable
- >"driver" files in C, rather than assembly language? In order to link my
- >C code, I need a main()?
- >
- What you can do is create an executable that you can also load as a device
- driver. This is only possible if your C compiler does not reorder the
- datasegment, i.e. if the first global variable you define is put at the start
- of the EXE file (Turbo C and Borlannd C++ work). The trick is to create a
- device driver header as the first global variable and set up the strategy and
- interrupt routines. You have to do a stack switch probably, as C programs
- usually are quite heavy on the stack. The device driver can be called by any
- program with a stack of e.g. 256 bytes, which might not be enough.
-
- The main() function can then simply say
- "Load me as a device driver:
- DEVICE=C:\BARF\DO_BARF.EXE
- "
- or something like that. I've used this trick for Turbo Pascal 6 and Turbo C
- 2.0 and higher and it works fine. The speed of the device driver is not all
- that good though, assembly is much faster then any C compiler I've gotten my
- hands on so far (including Borland C++ 4.5 and MS C++ 8)
-
- HTH,
-
- JJ
-
-
- ----------------------------------------------------------
- Jan Just (JJ) Keijser
- SMTP: jjk@lbvrtda.logica.com
- X400: C=GB A=ATTMAIL P=Logica O=LBV OU1=LBVRTDA S=JJK
- I prefer clear blue skies over a bunch of clouds any day
- My views are my own...
- ----------------------------------------------------------
-